package com.example.demo.repository;

import com.example.demo.domain.Discuss;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.awt.print.Pageable;
import java.util.List;
//@Mapper 要不要都行
public interface Repository  extends JpaRepository<Discuss,Integer> {
    //1查询author非空的Discuss评论集合
    public List<Discuss> findByAuthorNotNull();
    //2根据文字id分页查看Discuss集合
    @Query("select c from t_comment c where c.aId=?1")
    public List<Discuss> getDiscussPaged(Integer aid, Pageable pageable);
    //3表示用的原生sql语句
    @Query(value="select * from t_comment c where c.aId=?1",nativeQuery=true)
    public List<Discuss> getDiscussPaged2(Integer aid, Pageable pageable);
    //4根据评论id修改评论作者author
    @Transactional//增删改操作必须进行事务控制
    @Modifying//跟新或修改必须要加
    @Query("update t_comment c set c.author=?1 where c.id=?2")
    public int updateDiscuss(String authot,Integer id);
}
